package org.nf.chat.service;




import org.nf.chat.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = new User();
        user.setId(UUID.randomUUID().toString());
        user.setUserName(req.getParameter("userName"));
        //把用户信息保存到会话作用域
        req.getSession().setAttribute("user", user);
        //转发到聊天页面（主页），因为在WEB-INF目录中
        req.getRequestDispatcher("/WEB-INF/index.html").forward(req, resp);
    }
}
